﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using EMANIFEST.Dtos;

namespace TestSaveRecord
{
    /// <summary>
    /// Summary description for TestPassengerRecord
    /// </summary>
    [TestClass]
    public class TestPassengerRecord
    {
        public TestPassengerRecord()
        {
            //
            // TODO: Add constructor logic here
            //
        }
        eManifestService.EmanifestServiceClient client = new eManifestService.EmanifestServiceClient();

        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        //
        // You can use the following additional attributes as you write your tests:
        //
        // Use ClassInitialize to run code before running the first test in the class
        // [ClassInitialize()]
        // public static void MyClassInitialize(TestContext testContext) { }
        //
        // Use ClassCleanup to run code after all tests in a class have run
        // [ClassCleanup()]
        // public static void MyClassCleanup() { }
        //
        // Use TestInitialize to run code before running each test 
        // [TestInitialize()]
        // public void MyTestInitialize() { }
        //
        // Use TestCleanup to run code after each test has run
        // [TestCleanup()]
        // public void MyTestCleanup() { }
        //
        #endregion

        [TestMethod]
        public void TestPassenger()
        {
            try
            {
                PassengerDto pas = new PassengerDto();
                pas.PassengerId = new Guid("3A3A716B-9354-4F88-8647-DC82DA3EB95D");
                pas.DocumentId = new Guid("DAB27624-2270-4C40-A977-8856C4A8388A");
                pas.FamilyName = "Nguyen Tien";
                pas.GivenName = "Tan";
                pas.StateId = new Guid("1337a2c1-6530-4112-9142-c773dcb4a366");
                pas.CreaterId = new Guid("a6827a2d-2821-449d-9927-897e7ae5fb4e");
                pas.BirthDate = DateTime.Now;
                pas.BirthPlace = "Phuc Tho Viet Nam";
                pas.PassportNumber = "002";
                pas.PassportType = "T002";
                pas.PassportValidDate = DateTime.Now;
                pas.PortIdOfEmbarkation = new Guid("2630f7f9-2e1d-431c-9f19-6ba069d31ce7");
                pas.PortIdOfDisembarkation = new Guid("2630f7f9-2e1d-431c-9f19-6ba069d31ce7");
                pas.IsTransit = false;

               
                client.SavePassengerRecord(pas);

                PassengerDto pdto = client.GetPassengerById(pas.PassengerId);
                if (pdto != null)
                    Console.WriteLine("cap nhat thanh cong");
                else
                    Console.WriteLine("cap nhat fail");
            }
            catch(Exception ex)
            {
                Console.WriteLine(ex.InnerException.Message);
            }
        }


        [TestMethod]
        public void DeletePassenger()
        {
            try
            {
                ResponseDto res = client.DeletePassengerById(new Guid("3A3A716B-9354-4F88-8647-DC82DA3EB95D"));
                Console.WriteLine(res.IsSuccess);
                PassengerDto pdto = client.GetPassengerById(new Guid("3A3A716B-9354-4F88-8647-DC82DA3EB95D"));
                if (pdto == null)
                    Console.WriteLine("Delete thanh cong");
                else
                    Console.WriteLine("Delete that bai");
                
            }
            catch(Exception ex)
            {
                Console.WriteLine(ex.InnerException.Message);
            }
        }



        [TestMethod]
        public void TestPassengerByPortName()
        {
            try
            {
                PassengerDto pas = new PassengerDto();
                pas.PassengerId = Guid.NewGuid();
                pas.DocumentId = new Guid("DAB27624-2270-4C40-A977-8856C4A8388A");
                pas.FamilyName = "Nguyen Tien";
                pas.GivenName = "Tan";
                pas.StateId = new Guid("1337a2c1-6530-4112-9142-c773dcb4a366");
                pas.CreaterId = new Guid("a6827a2d-2821-449d-9927-897e7ae5fb4e");
                pas.BirthDate = DateTime.Now;
                pas.BirthPlace = "Phuc Tho Viet Nam";
                pas.PassportNumber = "002";
                pas.PassportType = "T002";
                pas.PassportValidDate = DateTime.Now;
                pas.PortIdOfEmbarkation = Guid.Empty;
                pas.PortIdOfDisembarkation = Guid.Empty;
                pas.PortNameOfDisembarkation = "C016";
                pas.PortNameOfEmbarkation = "C017";
                pas.IsTransit = false;


                client.SavePassengerRecord(pas);

                PassengerDto pdto = client.GetPassengerById(pas.PassengerId);
                if (pdto != null)
                    Console.WriteLine("cap nhat thanh cong");
                else
                    Console.WriteLine("cap nhat fail");
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.InnerException.Message);
            }
        }
    }
}
